package chenji.itemeditor.itemeditor;

import chenji.itemeditor.nbt.base.NBTTagCompound;

public class FireworkExplosion {
	private boolean flicker;
	private boolean trail;
	private int color;
	private int fadecolors;
	private FireworkType type;

	public FireworkExplosion() {
	}

	public FireworkExplosion(FireworkType type, int color) {
		this.type = type;
		if (color <= 0) {
			this.color = 1;
		} else {
			this.color = color;
		}

		this.flicker = false;
		this.trail = false;
		this.fadecolors = -1;
	}

	public FireworkExplosion setFadecolors(int fadecolors) {
		if (fadecolors <= 0) {
			return this;
		}
		this.fadecolors = fadecolors;
		return this;
	}

	public FireworkExplosion setTrail(boolean trail) {
		this.trail = trail;
		return this;
	}

	public FireworkExplosion setFlicker(boolean flicker) {
		this.flicker = flicker;
		return this;
	}

	public NBTTagCompound getTag() {
		NBTTagCompound c = new NBTTagCompound();
		c.setBoolean("Flicker", this.flicker);
		c.setBoolean("Trail", this.trail);
		c.setInt("Type", this.type.getID());
		c.setInt("Colors", this.color);
		if (!(fadecolors == -1)) {
			c.setInt("FadeColors", this.fadecolors);
		}
		return c;
	}

	public FireworkExplosion loadFromNBTTagCompound(NBTTagCompound n) {
		int type = n.getInt("Type");
		FireworkType t = FireworkType.getByID(type);
		if (t == null) {
			return null;
		}
		this.flicker = n.getBoolean("Flicker");
		this.trail = n.getBoolean("Trail");
		this.color = n.getInt("Colors");
		this.fadecolors = n.getInt("FadeColors");
		this.type = t;
		return this;

	}

	public FireworkType getType() {
		return this.type;
	}
}
